package com.lovo.boot.controller;


import com.lovo.boot.bean.Emp;
import com.lovo.boot.bean.Info;
import com.lovo.boot.dto.EmpInfoDto;
import com.lovo.boot.service.IEmpService;
import com.lovo.boot.service.IInfoService;
import com.lovo.boot.service.impl.EmpServiceImpl;
import com.lovo.boot.service.impl.InfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ren
 * @since 2022-03-22
 */
@RestController
public class EmpController {
    @Autowired
    private IEmpService empService;
    @Autowired
    private IInfoService infoService;
    @PutMapping("putEmp/{empId}/{post}/{salary}")
    public boolean updateEmp(@PathVariable("empId")Integer id, @PathVariable("post")String post, @PathVariable("salary")String salary){
        Emp emp = empService.getById(id);
        Info info=new Info();
        info.setIPost(emp.getENowpost());
        info.setISalary(emp.getENowsalary());
        info.setITime(LocalDateTime.now().toString());
        info.setFkEmpid(emp.getEId());
        emp.setENowpost(post);
        emp.setENowsalary(salary);
        boolean b = empService.updateById(emp);

        b = infoService.save(info);
        return b;
    }
    @GetMapping("getEmp/{id}")
    public List<Emp> getEmp(@PathVariable("id")int id){
        List<Emp> empListById = empService.findEmpListById(id);
        return empListById;
    }
    @GetMapping("all")
    public List<EmpInfoDto> getEmpAll(){
        return empService.findEmpList();
    }
    @GetMapping("getEmpByName/{name}")
    public List<EmpInfoDto> getEmpByName(@PathVariable("name")String name){
        List<EmpInfoDto> empListByName = empService.findEmpListByName(name);
        return empListByName;
    }
    @GetMapping("carIdGet/{cardId}")
    public String carIdGet(@PathVariable("cardId")String cardId){
        if(cardId.length()<5){
            return "身份证位数不够";
        }else {
            return "身份证验证成功";
        }
    }
    @PostMapping("carIdPost")
    public String carIdPost(String cardId){
        if(cardId.length()<5){
            return "身份证位数不够";
        }else {
            return "身份证验证成功";
        }
    }
}
